package com.yiyefanchen.ai.service.impl;

import com.yiyefanchen.ai.entity.vo.MessageVO;
import com.yiyefanchen.ai.service.DashScopeChatService;
import org.springframework.ai.chat.memory.ChatMemoryRepository;
import org.springframework.ai.chat.messages.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DashScopeChatServiceImpl implements DashScopeChatService {

    @Autowired
    ChatMemoryRepository chatMemoryRepository;

    @Override
    public List<String> findConversationIds() {
        return chatMemoryRepository.findConversationIds();
    }

    @Override
    public List<MessageVO> findByConversationId(String conversationId) {
        List<Message> messages = chatMemoryRepository.findByConversationId(conversationId);
        return messages.stream().map(MessageVO::new).toList();
    }

    @Override
    public void saveAll(String conversationId, List<Message> messages) {
        chatMemoryRepository.saveAll(conversationId, messages);
    }

    @Override
    public void deleteByConversationId(String conversationId) {
        chatMemoryRepository.deleteByConversationId(conversationId);
    }
}
